/* (c) 2013 Fyren, see license.txt */

#include "whatiah.h"

int main()
{
	initWhatiah();

	Deck pool =
	{
		charms[wornLeatherChest],
		charms[wornLeatherChest],
		charms[wornLeatherChest],
		charms[wornLeatherChest],
		charms[wornLeatherChest],
		charms[leatherPants],
		charms[leatherPants],
		charms[leatherPants],
		charms[leatherPants],
		charms[leatherPants],
		charms[bronzeHelm],
		charms[bronzeHelm],
		charms[bronzeHelm],
		charms[bronzeHelm],
		charms[bronzeHelm],
		charms[smallGlyph],
		charms[smallGlyph],
		charms[smallGlyph],
		charms[smallGlyph],
		charms[smallGlyph],
		charms[glyphedGloves],
		charms[glyphedGloves],
		charms[glyphedGloves],
		charms[glyphedGloves],
		charms[glyphedGloves],
		charms[shoulderGlyph],
		charms[shoulderGlyph],
		charms[shoulderGlyph],
		charms[shoulderGlyph],
		charms[shoulderGlyph],
		charms[ratCloak],
		charms[ratCloak],
		charms[ratCloak],
		charms[ratCloak],
		charms[ratCloak],
	};
		
	Mob *enemy = mobs[oldGoblin];
	while (true)
	{
		Deck curPool = pool;
		Deck d;
		while (d.size() <= enemy->maxSP)
		{
			std::uniform_int_distribution<> dis(0, curPool.size() - 1);
			int i = dis(*mt);
			Charm *ch = curPool[i];
			d.push_back(ch);
			curPool.erase(curPool.begin() + i);
		}
		std::sort(d.begin(), d.end(), [](Charm *a, Charm *b) { return a->id < b->id; });
		
		Mob *player = new Mob("Player", 56, d);
		
		int cd = 0;
		int dead = 0;
		int survive = 0;
		int spirit = 0;
		int nothing = 0;
		int fights = 10000;
		Fight f({player}, {enemy});
		for (int i = 0; i < fights; i++)
		{
			player->init();
			enemy->init();
			f.start();

			if (!player->alive) dead++;
			else if (player->SP <= floor(player->maxSP * 0.1) && player->HP <= floor(player->maxHP * 0.1)) cd++;
			else if (player->SP <= floor(player->maxSP * 0.1)) spirit++;
			else if (player->HP <= floor(player->maxHP * 0.1)) survive++;
			else nothing++;
		}

		if ((float) cd / fights > 0.42f) 
		{
			std::cout << (float) cd / fights << ": ";
			std::for_each(d.begin(), d.end() - 1, [](Charm *ch) { std::cout << ch->name <<  ", "; });
			std::cout << d.back()->name << std::endl;
		}
	}

        return 0;
}
